package com.lizhi.updata;

import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.List;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import com.alibaba.fastjson.JSON;
import com.lizhi.model.model2.SongModel;
import com.lizhi.util.Util;

public class ChangeSongProperty {
	private String url = "https://freebook.firebaseio.com/songs.json";
	private String originURL = "https://encourage.firebaseio.com/types/song/0.json";

	public ChangeSongProperty() {
		try {
			List<SongModel> bookModels;
			CloseableHttpClient httpClient = HttpClients.createDefault();
			HttpGet httpPost = new HttpGet(originURL);
			CloseableHttpResponse response = httpClient.execute(httpPost);
			InputStream inputStream = response.getEntity().getContent();
			bookModels = JSON.parseArray(Util.readStream(inputStream), SongModel.class);

			Util.clearData(originURL);

			Calendar calendar = Calendar.getInstance();
			calendar.set(2015, 3, 15, 10, 16);

			for (int i = 0; i < bookModels.size(); i++) {
				SongModel bookModel = bookModels.get(i);
				com.lizhi.model.SongModel bookModel2 = new com.lizhi.model.SongModel();
				bookModel2.author = bookModel.auther;
				bookModel2.brief = bookModel.des;
				bookModel2.id = bookModel.id;
				bookModel2.lyric = bookModel.des;
				bookModel2.name = bookModel.name;
				bookModel2.isFav = bookModel.isFav;
				bookModel2.songer = bookModel.songer;
				bookModel2.time = String.valueOf(calendar.getTimeInMillis());
				System.out.println(bookModel2.name + ":" + bookModel2.time);
				bookModel2.type = bookModel.type;
				calendar.add(Calendar.MILLISECOND, 1);
				if (i % 4 == 0) {
					calendar.add(Calendar.DAY_OF_MONTH, 1);
				}
				System.out.println(JSON.toJSONString(bookModel2));
				new UploadDataTask(url, JSON.toJSONString(bookModel2)).start();
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {

		new ChangeSongProperty();

	}

}
